<?php

namespace App\Http\Middleware;

use Closure;
use Symfony\Component\HttpKernel\Exception\HttpException;

class AllowMiddle
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (!is_local()) {
            if (!file_exists(allow_file())) {
                throw new HttpException(503);
            } else {
                return $next($request);
            }
        } else {
            return $next($request);
        }
    }
}
